const { get, getDistribution,addOrder ,cha} = require("../api/order.js")
var express = require('express');

var router = express.Router();

/* GET home page. */
router.get('/', async function (req, res, next) {
    const { curpage, eachPage } = req.query
    const data = await get({ curpage, eachPage })
    // console.log(data);
    res.send(data);
});

router.get("/getDistribution", async function (req, res, next) {
    const { id } = req.query;
    const data = await getDistribution(id);
    res.send(data);
});

router.post("/addOrders", async function (req, res, next) {
    const { 
        userId,
        shopId,
        distributionId,
        goodsArr,
        state,
        price } = req.body;
    await addOrder({
        userId,
        shopId,
        distributionId,
        goodsArr,
        state,
        price
    });
    res.send({ state: true });
});

router.post('/searchOrder', async function (req, res, next) {
    const { _id } = req.body
    const data = await cha({ _id });
    res.send(data);
});
module.exports = router;
